package com.ctg.itrdc.sysmgr.portal.control;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ctg.itrdc.sysmgr.portal.api.dto.SystemUserPostDTO;
import com.ctg.itrdc.sysmgr.portal.api.service.ISystemUserPostService;
import com.ctg.itrdc.sysmgr.portal.common.constant.DictEnum;
import com.ctg.itrdc.sysmgr.portal.common.entity.CommonResult;
import com.ctg.itrdc.sysmgr.portal.data.entity.SystemUserPost;
import com.ctg.itrdc.sysmgr.portal.exception.SysmgrContrlException;
import com.ctg.itrdc.sysmgr.portal.utils.DTOHelper;

@Controller
@RequestMapping("/system_user_post")
public class SystemUserPostController  extends SysmgrCURDController<Long, SystemUserPostDTO> {
    
	@Resource
	private ISystemUserPostService systemUserPostService;
	/**
	 * @api {get} /system_user_post/batch/insert 批量指定岗位
	 * @apiGroup system_user_post
	 * @apiName batchInsert
	 * @apiParam {String} ids sysPostid列表，用逗号隔开，如：x,y,z 
	 * @apiParam {String} sysUserId：系统用户标识 必传
	 * @apiParam {String} orgId：组织标识 必传
	 * @apiParam {String} statusCd 状态
	 * @apiVersion 0.0.1
	 */
	@RequestMapping("/batch/insert")
	@ResponseBody
	public CommonResult batchInsert(
			@RequestParam(required=false) String ids,
			@Valid SystemUserPostDTO dto,BindingResult result){
		
		if(StringUtils.isBlank(ids)){
			throw new SysmgrContrlException("sysPostId列表不能为空~");
		}
		DTOHelper.valid(result);
		DTOHelper.updateDTO(dto);
		
		dto.setStatusCd(DictEnum.StatusCd.S0A.toString());
		systemUserPostService.batchInsert(ids,dto);
		return new CommonResult(HttpStatus.OK.toString(),"批量新增成功");
	}
}
